home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 051-075 / disk_069 / make / main.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  5KB  |  228 lines

  1. /*
  2.  *    make [-f makefile] [-ins] [target(s) ...]
  3.  *
  4.  *    (Better than EON mk but not quite as good as UNIX make)
  5.  *
  6.  *    -f makefile name
  7.  *    -i ignore exit status
  8.  *    -n Pretend to make
  9.  *    -p Print all macros & targets
  10.  *    -q Question up-to-dateness of target.  Return exit status 1 if not
  11.  *    -r Don't not use inbuilt rules
  12.  *    -s Make silently
  13.  *    -t Touch files instead of making them
  14.  *    -m Change memory requirements (EON only)
  15.  */
  16.  
  17. #include <stdio.h>
  18. #include "h.h"
  19.  
  20. #ifdef unix
  21. #include <sys/errno.h>
  22. #endif
  23. #ifdef eon
  24. #include <sys/err.h>
  25. #endif
  26. #ifdef os9
  27. #include <errno.h>
  28. #endif
  29. #ifdef amiga
  30. #include <errno.h>
  31. #endif
  32.  
  33. #ifdef eon
  34. #define MEMSPACE    (16384)
  35. #endif
  36.  
  37.  
  38. char           *myname;
  39. char           *makefile;    /* The make file  */
  40. #ifdef eon
  41. unsigned        memspace = MEMSPACE;
  42. #endif
  43.  
  44. FILE           *ifd;        /* Input file desciptor  */
  45. bool            domake = TRUE;    /* Go through the motions option  */
  46. bool            ignore = FALSE;    /* Ignore exit status option  */
  47. bool            silent = FALSE;    /* Silent option  */
  48. bool            print = FALSE;    /* Print debuging information  */
  49. bool            rules = TRUE;    /* Use inbuilt rules  */
  50. bool            dotouch = FALSE;/* Touch files instead of making  */
  51. bool            quest = FALSE;    /* Question up-to-dateness of file  */
  52.  
  53.  
  54. void
  55. main(argc, argv)
  56.     int             argc;
  57.     char          **argv;
  58. {
  59.     register char  *p;        /* For argument processing  */
  60.     int             estat = 0;    /* For question  */
  61.     register struct name *np;
  62.     void            prt(), circh();
  63.  
  64.  
  65.     myname = (argc-- < 1) ? "make" : *argv++;
  66.  
  67.     while ((argc > 0) && (**argv == '-')) {
  68.     argc--;            /* One less to process  */
  69.     p = *argv++;        /* Now processing this one  */
  70.  
  71.     while (*++p != '\0') {
  72.         switch (*p) {
  73.         case 'f':        /* Alternate file name  */
  74.         if (*++p == '\0') {
  75.             if (argc-- <= 0)
  76.             usage();
  77.             p = *argv++;
  78.         }
  79.         makefile = p;
  80.         goto end_of_args;
  81. #ifdef eon
  82.         case 'm':        /* Change space requirements  */
  83.         if (*++p == '\0') {
  84.             if (argc-- <= 0)
  85.             usage();
  86.             p = *argv++;
  87.         }
  88.         memspace = atoi(p);
  89.         goto end_of_args;
  90. #endif
  91.         case 'n':        /* Pretend mode  */
  92.         domake = FALSE;
  93.         break;
  94.         case 'i':        /* Ignore fault mode  */
  95.         ignore = TRUE;
  96.         break;
  97.         case 's':        /* Silent about commands  */
  98.         silent = TRUE;
  99.         break;
  100.         case 'p':
  101.         print = TRUE;
  102.         break;
  103.         case 'r':
  104.         rules = FALSE;
  105.         break;
  106.         case 't':
  107.         dotouch = TRUE;
  108.         break;
  109.         case 'q':
  110.         quest = TRUE;
  111.         break;
  112.         default:        /* Wrong option  */
  113.         usage();
  114.         }
  115.     }
  116. end_of_args:;
  117.     }
  118.  
  119. #ifdef amiga
  120.     if ((ifd = fopen("s:builtins.make", "r")) != (FILE *) 0) {
  121.     input(ifd);
  122.     fclose(ifd);
  123.     } else
  124. #endif
  125.     makerules();
  126.  
  127. #ifdef eon
  128.     if (initalloc(memspace) == 0xffff)    /* Must get memory for alloc  */
  129.     fatal("Cannot initalloc memory");
  130. #endif
  131.  
  132.     if (!makefile) {    /* If no file, then use default */
  133.     if ((ifd = fopen(DEFN1, "r")) == (FILE *) 0)
  134. #ifdef eon
  135.         if (errno != ER_NOTF)
  136.         fatal("Can't open %s; error %02x", DEFN1, errno);
  137. #endif
  138. #ifdef unix
  139.     if (errno != ENOENT)
  140.         fatal("Can't open %s; error %02x", DEFN1, errno);
  141. #endif
  142. #ifdef amiga
  143.     if (errno != ENOENT)
  144.         fatal("Can't open %s; error %02x", DEFN1, errno);
  145. #endif
  146. #ifdef DEFN2
  147.     if ((ifd == (FILE *) 0)
  148.         && ((ifd = fopen(DEFN2, "r")) == (FILE *) 0))
  149.         fatal("Can't open %s", DEFN2);
  150. #else
  151.     else
  152.         fatal("Can't open %s", DEFN1);
  153. #endif
  154.     } else if (strcmp(makefile, "-") == 0)    /* Can use stdin as makefile  */
  155.     ifd = stdin;
  156.     else if ((ifd = fopen(makefile, "r")) == (FILE *) 0)
  157.     fatal("Can't open %s", makefile);
  158.  
  159.     setmacro("$", "$");
  160.  
  161.     while (argc && (p = index(*argv, '='))) {
  162.     char            c;
  163.  
  164.     c = *p;
  165.     *p = '\0';
  166.     setmacro(*argv, p + 1);
  167.     *p = c;
  168.  
  169.     argv++;
  170.     argc--;
  171.     }
  172.  
  173.     input(ifd);            /* Input all the gunga  */
  174.     fclose(ifd);        /* Finished with makefile  */
  175.     lineno = 0;            /* Any calls to error now print no line
  176.                  * number */
  177.  
  178.     if (print)
  179.     prt();            /* Print out structures  */
  180.  
  181.     np = newname(".SILENT");
  182.     if (np->n_flag & N_TARG)
  183.     silent = TRUE;
  184.  
  185.     np = newname(".IGNORE");
  186.     if (np->n_flag & N_TARG)
  187.     ignore = TRUE;
  188.  
  189.     precious();
  190.  
  191.     if (!firstname)
  192.     fatal("No targets defined");
  193.  
  194.     circh();            /* Check circles in target definitions  */
  195.  
  196.     if (!argc)
  197.     estat = make(firstname, 0);
  198.     else
  199.     while (argc--) {
  200.         if (!print && !silent && strcmp(*argv, "love") == 0)
  201.         printf("Not war!\n");
  202.         estat |= make(newname(*argv++), 0);
  203.     }
  204.  
  205.     if (quest)
  206.     exit(estat);
  207.     else
  208.     exit(0);
  209. }
  210.  
  211.  
  212. usage()
  213. {
  214.     fprintf(stderr, "Usage: %s [-f makefile] [-inpqrst] [macro=val ...] [target(s) ...]\n", myname);
  215.     exit(1);
  216. }
  217.  
  218.  
  219. void
  220. fatal(msg, a1, a2, a3, a4, a5, a6)
  221.     char           *msg;
  222. {
  223.     fprintf(stderr, "%s: ", myname);
  224.     fprintf(stderr, msg, a1, a2, a3, a4, a5, a6);
  225.     fputc('\n', stderr);
  226.     exit(1);
  227. }
  228.